//
//  TermConditionView.m
//  sensen_ios
//
//  Created by mc on 16/4/11.
//  Copyright © 2016年 pro. All rights reserved.
//


//条款与申明
#import "TermConditionView.h"

@implementation TermConditionView

- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.layer.cornerRadius = 20;
        self.backgroundColor = rgba(238, 237, 237, 1);
        self.userInteractionEnabled = YES;
        
        //标题
        UILabel *  headLabel = [[UILabel alloc] init];
        headLabel.textColor = [UIColor blackColor];
        [self  addSubview:headLabel];
        [headLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.mas_centerX);
            make.top.equalTo(self).offset(10);
            make.size.mas_equalTo(CGSizeMake(180, 25));
        }];
        headLabel.textColor = rgba(49, 42, 40, 1);
        headLabel.textAlignment = NSTextAlignmentCenter;
        headLabel.text = @"条款与申明";
        if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.2")) {
            headLabel.font = [UIFont systemFontOfSize:25];

        }else{
            headLabel.font = [UIFont systemFontOfSize:25];

        }
        //内容
        UILabel * contextLable = [[UILabel alloc] init];
        [self addSubview:contextLable];
        [contextLable mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.mas_centerX);
            make.centerY.equalTo(self.mas_centerY).offset(-20);
            make.size.mas_equalTo(CGSizeMake(frame.size.width - 40, frame.size.height / 2 + 20));
        }];
        
        NSString * context = @"  您将使用森森公司的鱼保姆监控，为了保证您能正常观看您的鱼缸以及AQ鱼缸姆设备正常运行，在使用过称中需要联网以及手机您的个人信息，我们保证不会把您的个人信息透漏给任何第三方，出于对您的个人信息安全的考虑，您有必要阅读本隐私协议。您是否同意此项协议？";
        contextLable.numberOfLines = 0;
        if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.2")) {
           contextLable.font = [UIFont systemFontOfSize:15 weight:1];
        }else{
           contextLable.font = [UIFont systemFontOfSize:15];
        }

        
        NSMutableAttributedString * attributedString = [[NSMutableAttributedString alloc] initWithString:context];
        NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        [paragraphStyle setLineSpacing:5];
        [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [context length])];
        [contextLable setAttributedText:attributedString];
        [contextLable sizeToFit];
        
        
        
        _selectButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_selectButton setImage:[UIImage imageNamed:@"购物车_未选中"] forState:UIControlStateNormal];
        [_selectButton setImage:[UIImage imageNamed:@"购物车_选中"] forState:UIControlStateSelected];
        [_selectButton addTarget:self action:@selector(selectAction:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_selectButton];
        [_selectButton mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.top.equalTo(contextLable.mas_bottom).offset(10);
            make.left.equalTo(contextLable.mas_left).offset(0);
            make.size.mas_equalTo(CGSizeMake(20, 20));
        }];
        
        
        
        
        //提示按钮
        UILabel * prompt = [[UILabel alloc] init];
        
        [self addSubview:prompt];
        [prompt mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_selectButton.mas_top).offset(0);
            make.left.equalTo(_selectButton.mas_right).offset(10);
            make.size.mas_equalTo(CGSizeMake(100, 20));
        }];
        
        prompt.numberOfLines = 0;
       if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.2")) {
             prompt.font = [UIFont systemFontOfSize:13 weight:1];
        }else{
            prompt.font = [UIFont systemFontOfSize:13];
        }
        prompt.text = @"不再提示";
        self.segmentedControl = [[UISegmentedControl alloc] initWithItems:@[@"取消",@"确定"]];
        [self addSubview:self.segmentedControl];
        [self.segmentedControl mas_makeConstraints:^(MASConstraintMaker *make) {

            make.top.equalTo(prompt.mas_bottom).offset(8);
            make.size.mas_equalTo(CGSizeMake(250, 35));
            make.centerX.equalTo(self.mas_centerX);
        }];
        
        self.segmentedControl.tintColor = [UIColor blackColor];
        [self.segmentedControl setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:14], NSFontAttributeName, nil] forState:UIControlStateNormal];
        self.segmentedControl.layer.borderWidth = 1;
        self.segmentedControl.layer.masksToBounds = YES;
        self.segmentedControl.layer.cornerRadius = 10.0;
    }
    return self;
}

- (void)selectAction:(UIButton *)button{
    button.selected = !button.selected;
}





@end
